package org.springcloud.wisdom.springcloud_03_freshman.admin.dao;

import org.apache.ibatis.annotations.*;
import org.springcloud.wisdom.springcloud_03_freshman.index.login.entity.Freshman;

import java.util.List;

@Mapper
public interface AdminFreshmanDao {
    /**
     *更新新生的地址、邮箱、联系方式 头像
     * 调用 FreshmanDao中的UpdateFreshmanBySid
     */


    /**
     * 以分页的形式查看 新生信息
     * @param start 页码数
     * @param size 每页记录数
     * @param sname  姓名
     * @param dept 院系
     * @param sid 学号
     * @return
     */
    @Select("<script>" +
            "SELECT * FROM freshman" +
            "  <where>" +
            " del=0"+
            "    <if test=\"sname != null\">" +
            "     and sname = #{sname}" +
            "    </if>" +
            "    <if test=\"dept != null\">" +
            "      and dept = #{dept} " +
            "    </if>" +
            "    <if test=\"sid != null\">" +
            "      and sid = #{sid} " +
            "    </if>" +
            "</where>"+
            "limit #{start},#{size}"+
            "</script>")
    public List<Freshman> getFreshmanByCons(int start, int size, String sname, Integer dept, String sid);

    @Select("<script>" +
            "SELECT count(*) FROM freshman" +
            "  <where>" +
            " del=0 "+
            "    <if test=\"sname != null\">" +
            "     and sname = #{sname}" +
            "    </if>" +
            "    <if test=\"dept != null\">" +
            "     and dept = #{dept} " +
            "    </if>" +
            "    <if test=\"sid != null\">" +
            "      and sid = #{sid} " +
            "    </if>" +
            "</where>"+
            "</script>")
    public int countFreshman(String sname,Integer dept,String sid);

    /**
     * 根据唯一标识 删除新生
     * @param id
     * @return
     */
    @Update("update freshman set del=1 where id=#{id}")
    public int deleteFresh(Integer id);

    /**
     * 删除多个新生
     */
    @Update("<script>" +
            "  update freshman set del=1 where ID in" +
            "  <foreach collection=\"ids\" item=\"did\" open=\"(\" close=\")\" separator=\",\">" +
            "    #{did}" +
            "   </foreach>" +
            "</script>")
    public int delbyIds(List<Integer> ids);
}
